package com.hq.hotl;


import com.github.pagehelper.PageException;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConverter implements Converter<String, Date> {
    private Date source;

    public StringToDateConverter(Date source) {
        this.source = source;
    }

    public StringToDateConverter() {
    }

    @Override
    public Date convert(String s) {
        if(s==null){
            throw new RuntimeException("传入参数不能为空");
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try{
            return sdf.parse(s);
        }catch (ParseException e){
            e.printStackTrace();
            throw new RuntimeException("字符串格式错误");
        }
    }
}
